from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import ast
import os
import argparse
from datetime import datetime


def get_parser(parser=None):
    PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

    def str_list(x):
        return x.split(',')

    def int_list(x):
        resize_list = list(map(int, x.replace('[', '').replace(']', '').split(',')))
        if len(resize_list) < 2:
            return [resize_list[0], resize_list[0]]
        elif len(resize_list) == 2:
            return list(map(int, x.replace('[', '').replace(']', '').split(',')))
        else:
            raise argparse.ArgumentTypeError('Unsupported value encountered.')

    def str2bool(v):
        if v.lower() in ('yes', 'true', 't', 'y', '1'):
            return True
        elif v.lower() in ('no', 'false', 'f', 'n', '0'):
            return False
        else:
            raise argparse.ArgumentTypeError('Unsupported value encountered.')

    if parser is None:
        parser = argparse.ArgumentParser("flags for cnn benchmark")

    parser.add_argument("--model_load_dir", type=str, default="/usr/src/ultralytics/yolov8n.pt", help="训练使用模型路径")
    parser.add_argument("--train_out", type=str, default='/workspace/model-out', help="训练输出")
    parser.add_argument("--train_model_out", type=str, default="default", help="训练模型输出")
    parser.add_argument("--data_url", type=str, default='/usr/local/work/dog.jpg', help="数据集路径")
    parser.add_argument("--data_val_url", type=str, default='/usr/local/work/dog.jpg', help="验证数据集路径")
    parser.add_argument("--gpu_num_per_node", type=int, default=1)

    return parser


def print_args(args):
    print("=".ljust(66, "="))
    print("Running {}: num_gpu_per_node = {}, num_nodes = {}.".format(
        args.model_name, args.gpu_num_per_node, args.num_nodes))
    print("=".ljust(66, "="))
    for arg in vars(args):
        print("{} = {}".format(arg, getattr(args, arg)))
    print("-".ljust(66, "-"))
    print("Time stamp: {}".format(
        str(datetime.now().strftime("%Y-%m-%d-%H:%M:%S"))))


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()
    print_args(args)